#!/usr/bin/perl -w
# Configure S.M.A.R.T.
# vim:tw=100 sw=2 expandtab ft=perl

return if i_has('no_smart');
return unless i_has("smart_disks");

my $text;
foreach (i_isa_fetchall("smart_disks")) {
  for (my $i = 0; $i < @$_; $i += 2) {
    my($disk, $driver) = ($_->[$i], $_->[$i + 1]);
    next unless $disk && $driver;
    $text .= "$disk -a -o on -H -S on -d $driver -m root\n";
  }
}

return unless $text;

$m{$hostname}{_smart_configured_} = 1;

if (i_distro("debian", "ubuntu")) {
  package_check("smartmontools");
  text_install("/etc/smartd.conf", $text, "/etc/init.d/smartmontools restart");
} elsif (i_distro("redhat")) {
  package_check("kernel-utils");
  text_install("/etc/smartd.conf", $text, "/etc/init.d/smartd restart");
  command("chkconfig smartd on");
} else {
  w "Can't deal with SMART configuration";
}

